package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: sky-take-out
 * @package: com.sky.controller.admin
 * @className: DishController
 * @author: Eric
 * @description: TODO
 * @date: 2023/9/22 10:14
 * @version: 1.0
 */
@RestController
@RequestMapping("/admin/dish")
@RequiredArgsConstructor
public class DishController {
    private final DishService dishService;

    /**
     * 创造
     *
     * @param dishDTO 盘d去
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping
    public Result<?> creat(@RequestBody DishDTO dishDTO){
        dishService.creat(dishDTO);
        return Result.success();
    }

    /**
     * 页面
     *
     * @param dishPageQueryDTO 菜盘页面查询d去
     * @return {@link Result}<{@link PageResult}>
     */
    @GetMapping("/page")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO){
        PageResult pageResult = dishService.page(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 按id删除批处理
     *
     * @param ids ids
     * @return {@link Result}<{@link ?}>
     */
    @DeleteMapping
    public Result<?> deleteBatchByIds(@RequestParam List<Long> ids){
        dishService.deleteBatchByIds(ids);
        return Result.success();
    }

    /**
     * 查询盘
     *
     * @param id id
     * @return {@link Result}<{@link DishVO}>
     */
    @GetMapping("/{id}")
    public Result<DishVO> queryDish(@PathVariable Long id){
        DishVO dishVO = dishService.queryDish(id);
        return Result.success(dishVO);
    }

    /**
     * 更新盘
     *
     * @param dishDTO 盘d去
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping
    public Result<?> updateDish(@RequestBody DishDTO dishDTO){
        dishService.updateDish(dishDTO);
        return Result.success();
    }

    /**
     * 更改状态
     *
     * @param id     id
     * @param status 状态
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("status/{status}")
    public Result<?> changeStatus(Long id,@PathVariable Integer status){
        dishService.changeStatus(id,status);
        return Result.success();
    }

    /**
     * 按类别id查询菜品
     *
     * @param categoryId 类别id
     * @return {@link Result}<{@link List}<{@link Dish}>>
     */
    @GetMapping("/list")
    public Result<List<Dish>> queryDishByCategoryId(Long categoryId){
        List<Dish> dish = dishService.queryDishByCategoryId(categoryId);
        return Result.success(dish);
    }
}
